package com.yz.group1.group_1.controller;

import com.yz.group1.group_1.entity.Doctor2;
import com.yz.group1.group_1.service.Doctor2Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@CrossOrigin()
@RestController
@RequestMapping("/doctor2")
public class Doctor2Controller {

    @Autowired
    private Doctor2Service doctor2Service;

    @GetMapping
    public List<Doctor2> doctorList() {
        // 修正：使用注入的doctorService实例调用方法
        return doctor2Service.listAllDoctor();
    }

    @PostMapping("/updateStatus")
    public boolean updateStatus(@RequestBody Doctor2 doctor2) {
        // 修正：参数名改为doctor，与方法参数一致
        return doctor2Service.updateById(doctor2);
    }

    @DeleteMapping("/delete/{id}")
    public boolean deleteBybId(@PathVariable Integer id) {
        return doctor2Service.removeById(id);
    }


    @PostMapping("/update")
    public boolean updateDoctor(@RequestBody Doctor2 doctor2) {
        // 调用 service 的更新方法（需确保 DoctorService 有对应实现）
        return doctor2Service.updateById(doctor2);
    }
    @PostMapping("/add")
    public boolean addDoctor(@RequestBody Doctor2 doctor2) {
        // 确保 departmentId 不为空（根据业务需求调整）
        if (doctor2.getDepartmentId() == null || doctor2.getDepartmentId().isEmpty()) {
            return false;
        }
        return doctor2Service.save(doctor2);
    }
}








